import { useSelector, useDispatch } from 'react-redux';
import { View } from '@tarojs/components';
import { setTabbarIndex } from '@/store/system-slice';
import { useShareAppMessage, useShareTimeline } from '@tarojs/taro';
import { domain2 } from '@/constant';
import TabbarBottom from '@/components/tabbar-bottom';
import Home from './home';
// import Map from './map';
import Order from './order';
import Mine from './mine';
// import { getUser } from '@/utils/user';

import './index.less';

const pageMap = [<Home />, <Order />, <Mine />];

export default function Index() {
  const tabbarIndex = useSelector((state: any) => state.system.tabbarIndex);
  // const user = getUser();
  const dispatch = useDispatch();

  const onTabbarChange = (index: number) => {
    dispatch(setTabbarIndex(index));
  };

  useShareAppMessage(() => ({
    title: '多多帮，让生活更美好',
    path: '/pages/index/index',
    imageUrl: `${domain2}/banner1.png`,
  }));

  useShareTimeline(() => ({
    title: '多多帮，让生活更美好',
    path: '/pages/index/index',
    imageUrl: `${domain2}/banner1.png`,
  }));

  return (
    <View className="index">
      {/* <UserMask user={user} /> */}
      <View className="content">{pageMap[tabbarIndex]}</View>
      <TabbarBottom value={tabbarIndex} onChange={onTabbarChange} />
    </View>
  );
}
